package com.geping.etl.common.security.authentication;

import javax.servlet.http.HttpServletRequest;
import java.util.TreeSet;

/***
 *
 * 鉴权处理器存储容器
 * @author liang.xu
 * @date 2021.8.3
 */
public abstract class AuthServiceContainer{

    /**
     * 鉴权服务列表
     */
    private static TreeSet<BasicAuthService>authServices=new  TreeSet<>();


    public AuthServiceContainer(){
        BasicAuthService  basicAuthService= (BasicAuthService) this;
        authServices.add(basicAuthService);
    }

    /**
     * 进行鉴权处理,第一个鉴权成功，即成功，否则进行下一个鉴权判断
     * @param url
     * @param request
     * @return
     */
    public static boolean doAuth(String url, HttpServletRequest request) {
        for(BasicAuthService basicAuthService:authServices){
            if(basicAuthService.auth(url,request)){
                return true;
            }
        }
        return false;
    }
}